//
//  TCShopDetailViewController.m
//  Project_B
//
//  Created by dllo on 15/12/1.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "TCShopDetailViewController.h"
#import "MyAnnotation.h"
@interface TCShopDetailViewController ()



@property (nonatomic, strong)CLLocationManager *locManager;


@property (strong, nonatomic) UILabel *lonLabel;
@property (strong, nonatomic) UILabel *latLabel;
@property (nonatomic, assign)CLLocationCoordinate2D coords;

@end

@implementation TCShopDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-daohang"] style:UIBarButtonItemStylePlain target:self action:@selector(makeMap)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui@2x"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.map= [[MKMapView alloc] initWithFrame:[self.view bounds]];
    self.map.mapType = MKMapTypeStandard;
    [self.view addSubview:self.map];
    self.coords = CLLocationCoordinate2DMake([self.dic[@"latitude"]floatValue ], [self.dic[@"longitude"] floatValue]);
    float zoomLevel = 0.005;
    MKCoordinateRegion region = MKCoordinateRegionMake(self.coords, MKCoordinateSpanMake (zoomLevel, zoomLevel));
    [self.map setRegion:[_map regionThatFits:region] animated:YES];
    MyAnnotation *annotation = [[MyAnnotation alloc] initWithCoordinate:self.coords];
    annotation.title = self.dic[@"title"];
    [_map addAnnotation:annotation];
}
- (void)makeMap
{
    CLLocationCoordinate2D end = CLLocationCoordinate2DMake([self.dic[@"latitude"]floatValue ], [self.dic[@"longitude"] floatValue]);
     MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
    MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:end addressDictionary:nil]];
    toLocation.name = self.dic[@"title"];
    [MKMapItem openMapsWithItems:@[currentLocation,toLocation] launchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey:[NSNumber numberWithBool:YES]}];
}

- (void)backAction
{
    [self.map removeFromSuperview];
    self.map = nil;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)dealloc
{
    self.map.delegate = nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
